package club.kunlingou.dsc.common.service.impl;

import java.util.List;

import org.jboss.logging.Logger;

import club.kunlingou.dsc.common.dao.BaseDao;
import club.kunlingou.dsc.common.domain.BaseEntity;
import club.kunlingou.dsc.common.service.BaseService;

public abstract class BaseServiceImpl<T extends BaseEntity> implements BaseService<T>{
	
	private static final Logger logger = Logger.getLogger(BaseServiceImpl.class);
	
	public abstract BaseDao<T> getDao();
	
	public T get(Long id) {
		return getDao().get(id);
	}
	
	public boolean save(T t) {

		try {
			if(t.getId() ==null) {
				getDao().insert(t);
			}else {
				getDao().update(t);
			}
			return true;
		}catch (Exception e) {
			logger.error(e);
			return false;
		}
	}
	
	public List<T> list(T query){
		return getDao().list(query);
	}
}
